<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>理财包</title>

    <link href="../plugin/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.css" rel="stylesheet"/>
    <link href="../plugin/sweetalert-6.6.2/sweetalert2.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
    <link href="../plugin/jquery-zoomify/zoomify.min.css" rel="stylesheet"/>

    <script src="../plugin/jquery-3.2.1/jquery-3.2.1.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/local_zh.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="../plugin/sweetalert-6.6.2/sweetalert2.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.formautofill.min.js"></script>
    <script src="../plugin/jquery-zoomify/zoomify.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.serializejson.js"></script>
    <script src="../plugin/soul/utils3.js"></script>
    <script src='../base/base.js'></script>
</head>

<body>
<div class="modal fade" data-backdrop="static" id="exchange_rate_modal_content">
    <div class="modal-dialog modal-lg ">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>数据源</b>
                </h4>
            </div>
            <div class="panel-body">
                <div class="form-group"><label class="col-sm-2 control-label">数据源</label>
                    <div class="col-sm-9">
                        <form id="dataForm">
                            <select class="form-control" id="dataStatus" name="dataStatus" class="form-control">
                                <option value="1">bcex</option>
                                <option value="2">digifinex</option>
                                <option value="3">bcexproxy</option>
                            </select>
                        </form>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" onclick="exchange_rate.save()">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $(function () {
        var resp = AjaxUtil.isLogin();
        if (!resp) return;
        var module = 'exchange_rate';// 权限模块
        var query = [];
        var toolbar = {
            default: [false, false, true, false],// back;add;edit;remove
            dialog: [50, 2, 9],//对话框参数:模态框宽度(百分比);表单标题宽度;表单输入框宽度
            extra: [{
                name: '数据源',
                glyphicon: 'list',
                onclick: 'dataStatus',
            }
            // ,{
            //     name: '是否为基础汇率',
            //     glyphicon: 'list',
            //     onclick: 'rateStatus',
            // }
            ]
        };
        var formElement = [{
            action: [false, true],
            type: 'hidden', // 表单类型
            name: 'exchangeRateVoId', // 字段名称
        }, {
            action: [false, true],
            type: 'text',
            label: '基础汇率',
            name: 'rate',
        }, {
            action: [false, true],
            id: 'expires',
            type: 'datetime',
            label: '缓存有效时间',
            name: 'expires',
            }
        ];

        var bootstrapTable = {
            url: '',
            columns: [{
                radio: true
            }, {
                field: 'name',
                title: '名称',
                align: 'center',
            }, {
                field: 'rate',
                title: '基础汇率',
                align: 'center',
            }, {
                field: 'expires',
                title: '缓存有效时间',
                align: 'center',
                formatter: BootstrapTableUtil.formatter.datetime
            }, {
                field: 'dateStatus',
                title: '数据源',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return 'bcex';
                    } else if (value == 2) {
                        return 'digifinex';
                    } else if (value == 3) {
                        return 'bcexproxy';
                    } else {
                        return '未知';
                    }
                }
            }, {
                field: 'isRate',
                title: '是否为基础汇率',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '是';
                    } else if (value == 2) {
                        return '否';
                    } else {
                        return '未知';
                    }
                }
            }]
        }

        exchange_rate = SingleTablePageCreateUtil.createInstance(module, query, toolbar, formElement, bootstrapTable);

        exchange_rate.dataStatus = function () {
            $('#exchange_rate_modal_content').modal('show');
        }

        exchange_rate.save = function () {
            var val = $('#dataStatus option:selected') .val();
            var resp = AjaxUtil.postJson('exchange_rate/editData', {
                dateStatus: val
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#exchange_rate_table').bootstrapTable('refresh');
                $('#exchange_rate_modal_content').modal('hide');
            }
        }

        exchange_rate.rateStatus = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#exchange_rate_table');
            if (!row) return false;
            var resp = AjaxUtil.postJson('exchange_rate/rateStatus',{
                exchangeRateVoId: row.exchangeRateVoId
            });
            if (resp) {
                $('#exchange_rate_table').bootstrapTable('refresh');
            }
        }

        exchange_rate.onEditModalShowBefore = function (row) {
            row.expires = FormatUtil.formatDateTime(row.expires);
            return row;
        };
    });
</script>
</html>